<?php
class dash extends userBase {
    function indexTask(){
        $this->articleTask();
    }

    function articleTask($menu_id=null,$page=1){
        $menuMode=MenuModule::init();
        $articleMode=ArticleMode::init();
        $url=WebRouter::init()->getQuestion(array("menu_id"=>$menu_id))."&page=#page#";
        $page=new Page($page,$url);
        // 查询文章
        $sonMenu=$menuMode->getPosterity($menu_id);
        list($result['article'],$total)=$articleMode->getList(null,array('menu_id'=>$sonMenu),
            array(),$page->getPageSize(),$page->getOffset());
        $page->setTotal($total);
        // 设置页码
        $result['page']=$page->getWidget()->setDisplayContent(false,false,true);
        View::displayAsHtml($result,"article.php");
    }

    function addTask($id=0){
        $result=array();
        $menuMode=MenuModule::init();
        $articleMode=ArticleMode::init();
        $result['detail']=$articleMode->getDetail($id);
        $result['menu']=$menuMode->getMenuTree();
        View::displayAsHtml($result,"add.php");
    }

    function addSubmitTask($title,$menu_id,$publish_time,$content){
        if(empty($title)|| empty($content)|| empty($publish_time)){
            View::displayAsTips(null,"信息填写不完整");
            return;
        }
        $up=Uploader::init();
        list($upRe,$pic)=$up->upImage("pic",null,array("set"=>"thumb","width"=>190,"height"=>128));
        $pic_url=strtolower($upRe)=="success"? $pic['url']: "";
        $user_id=$this->user->getLoginId();
        $data=array(
            'id'=>0,
            'title'=>$title,
            "pic_url"=>$pic_url,
            "owner"=>$user_id,
            'menu_id'=>$menu_id,
            'publish_time'=>$publish_time,
            'content'=>$content,
        );
        $articleMode=ArticleMode::init();
        $updateRe=$articleMode->update($data);
        if($updateRe->judgeState()){
            $url=WebRouter::init()->getAction("article");
            View::displayAsTips($url,$updateRe->getTitle());
        }else{
            View::displayDataMessage($updateRe);
        }
    }

    function userInfoTask(){
        $result['user_info']=$this->user->getLoginInfo();
        View::displayAsHtml($result,"fragment/user_information.php");
    }
}